package com.example.springvalidatesample2

import jakarta.validation.Valid
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping
@Validated
class CarController {
    @Autowired
    lateinit var repository: CarRepository

    @RequestMapping(value = ["addCar1"], method = [RequestMethod.POST])
    fun addCar1(@RequestBody @Valid car: Car): ResponseResult {
        repository.save(car)
        return ResponseResult("添加成功")
    }
}
